package com.kaussoft.lolblog.vo;

import java.io.Serializable;
import java.util.Set;

/** 
 * 		@hibernate.class
 * 		 table="ARTICLE"
 */
public class Article implements Serializable {

	// serialVersionUID
	private static final long serialVersionUID = 1L;
	
	// hashCode
	private int hashCode = Integer.MIN_VALUE;

	// primary key
	private Integer articleid;
	
	// fields
	private String articletitle;
	private String articlecontent;
	private String articledesc;
	
	// many to one
	private Part belongToPart;
	private Wblog belongToWblog;
	
	// collections
	private Set<Reply> replies;
	
	/** default constructor */
	public Article() {
		
	}
	
	/** primary key constructor */
	public Article(Integer articleid) {
		this.setArticleid(articleid);
	}
	
	/** required fields constructor */
	public Article(Integer articleid, String articledesc, 
			String articlecontent) {
		this.setArticleid(articleid);
		this.setArticledesc(articledesc);
		this.setArticlecontent(articlecontent);
	}

	/**
	 * 		@hibernate.property
	 * 		 column="ARTICLE_CONTENT"
	 */
	public String getArticlecontent() {
		return articlecontent;
	}

	public void setArticlecontent(String articlecontent) {
		this.articlecontent = articlecontent;
	}

	/**
	 * 		@hibernate.property
	 * 		 column="ARTICLE_DESC"
	 */
	public String getArticledesc() {
		return articledesc;
	}

	public void setArticledesc(String articledesc) {
		this.articledesc = articledesc;
	}

	/**
	 * 		@hibernate.id
	 * 		 column="ARTICLE_ID"
	 * 		 generator-class="native"
	 * 		 type="java.lang.Integer"
	 * 		 unsaved-value=null
	 * 		@hibernate.generator-param name="sequence" value="SQ_ARTICLE_ID"
	 */
	public Integer getArticleid() {
		return articleid;
	}

	public void setArticleid(Integer articleid) {
		this.articleid = articleid;
		this.hashCode = Integer.MIN_VALUE;
	}

	/**
	 * 		@hibernate.property
	 * 		 column="ARTICLE_TITLE"
	 */
	public String getArticletitle() {
		return articletitle;
	}

	public void setArticletitle(String articletitle) {
		this.articletitle = articletitle;
	}

	/**
	 * 		@hibernate.set
	 * 		 lazy="true"
     *       inverse="true"
     *       cascade="all-delete-orphan"
     *      @hibernate.key
     *       column="ARTICLE_ID"
     *      @hibernate.one-to-many
     *       class="com.kaussoft.lolblog.vo.Reply"
	 */
	public Set<Reply> getReplies() {
		return replies;
	}

	public void setReplies(Set<Reply> replies) {
		this.replies = replies;
	}
	
	/**
	 *		@hibernate.many-to-one
	 *		 column="PART_ID"
	 *		 class="com.kaussoft.lolblog.vo.Part"
	 */
	public Part getBelongToPart() {
		return belongToPart;
	}

	public void setBelongToPart(Part belongToPart) {
		this.belongToPart = belongToPart;
	}

	/**
	 *		@hibernate.many-to-one
	 *		 column="WBLOG_ID"
	 *		 class="com.kaussoft.lolblog.vo.Wblog"
	 *		 not-null="true"
	 */
	public Wblog getBelongToWblog() {
		return belongToWblog;
	}

	public void setBelongToWblog(Wblog belongToWblog) {
		this.belongToWblog = belongToWblog;
	}
	
	public boolean addToReplies(Object obj) {
		if (null == obj)
			return false;
		if (!(obj instanceof Reply)) 
			return false;
		else {
			Reply aObj = (Reply)obj;
			if (null == this.replies) 
				this.replies = new java.util.HashSet<Reply>();
			return this.replies.add(aObj);
		}
	}

	public boolean equals(Object obj) {
		if (null == obj) 
			return false;
		if (!(obj instanceof Article)) 
			return false;
		else {
			Article aObj = (Article) obj;
			if (null == this.getArticleid() || null == aObj.getArticleid()) 
				return false;
			else 
				return (this.getArticleid().equals(aObj.getArticleid()));
		}
	}
	
	public int hashCode() {
		if (Integer.MIN_VALUE == this.hashCode) {
			if (null == this.getArticleid()) 
				return super.hashCode();
			else {
				String hashStr = this.getClass().getName() + ":" + this.getArticleid().hashCode();
				this.hashCode = hashStr.hashCode();
			}
		}
		return this.hashCode;
	}

	public String toString() {
		return super.toString();
	}
	
}
